package com.example.r2022913.controller.WxController;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.r2022913.common.ApiRestResponse;
import com.example.r2022913.model.entity.WxEntity.TypeEntity;
import com.example.r2022913.service.WxService.TypeService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("wx/wc")
@Api(tags = "wx小程序服务  TypeController")
@Slf4j
public class TypeController {
    @Autowired
    TypeService typeService;

    //查询所有
    @RequestMapping("/typeList")
    public ApiRestResponse typeList(@RequestParam(defaultValue = "1") Integer pageNum,
                                    @RequestParam(defaultValue = "5") Integer pageSize,
                                    @RequestParam(defaultValue = "") Map<String, Object> params) {
        Integer typeCount = typeService.typeCount();
        if (pageNum == 2) {
            IPage page = typeService.typeList(pageNum, typeCount, params);
            return ApiRestResponse.success(page);
        }

        IPage page = typeService.typeList(pageNum, pageSize, params);
        return ApiRestResponse.success(page);
    }

    //指定id查询
    @RequestMapping("/typeById")
    public TypeEntity typeById(@RequestParam Long typeId) {
        return typeService.typeById(typeId);
    }
}


